package com.imcode;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

public class ReaderDemo02 {
    public static void main(String[] args) throws IOException {
        //1.创建一个按字符读取文件的对象
        Reader fr = new FileReader("D:\\file\\fw.txt");
        //2.定义一个字符数组
        char[] chars = new char[3];

        // read方法返回的是每次读取到的字符的个数
        /*
        System.out.println(fr.read(chars));//3
        System.out.println(fr.read(chars));//3
        System.out.println(fr.read(chars));//1
        System.out.println(fr.read(chars));//-1*/

        /*
        fr.read(chars);
        for (int i = 0; i < chars.length; i++) {
            System.out.println(chars[i] + ".");
        }*/

        /*
        while (fr.read(chars) != -1) {
            System.out.println(new String(chars) + ".");
        }*/

        int len = 0;
        while ((len = fr.read(chars)) != -1) {
            System.out.println(new String(chars,0,len) + ".");
        }
        fr.close();
    }
}
